package com.atguigu.stgy.admin.controller;

import com.atguigu.stgy.admin.service.ApartmentInfoService;
import com.atguigu.stgy.model.dto.ApartmentDTO;
import com.atguigu.stgy.model.dto.ApartmentSearchDTO;
import com.atguigu.stgy.model.entity.ApartmentInfo;
import com.atguigu.stgy.model.result.R;
import com.atguigu.stgy.model.vo.ApartmentVO;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("admin/apartment")
public class ApartmentInfoController {


    @Resource
    ApartmentInfoService apartmentInfoService;

    // http://localhost:8080/admin/apartment/saveOrUpdate
    @PostMapping("saveOrUpdate")
    public R saveOrUpdate(@RequestBody ApartmentDTO apartmentDTO) {
        apartmentInfoService.saveOrUpdateApartmentDTO(apartmentDTO);
        return R.ok();
    }

// /admin/apartment/pageItem

    @Operation(summary = "查询公寓信息列表")

    @GetMapping("pageItem")
    public R<Page<ApartmentVO>> pageItem(ApartmentSearchDTO searchDTO) {
        Page<ApartmentVO> page = apartmentInfoService.pageItem(searchDTO);
        return R.ok(page);
    }



  //  http://localhost:8080/admin/apartment/updateReleaseStatusById?id=9&status=0
    @Operation(summary = "新增/更新公寓信息")
    @PostMapping("updateReleaseStatusById")
    public  R  updateReleaseStatusById(@RequestParam("id")Long id, @RequestParam("status")Integer status){
       apartmentInfoService.update(Wrappers.lambdaUpdate(ApartmentInfo.class)
               .eq(ApartmentInfo::getId,id)
               .set(ApartmentInfo::getIsRelease,status)
               .set(ApartmentInfo::getUpdateTime,new Date()));

       return R.ok();
    }


}
